package com.example.emailcraft.controller;

import com.example.emailcraft.entity.request.EmailRequest;
import com.example.emailcraft.service.IEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/v1/emails")
public class SendEmailController {
    @Autowired
    public IEmailService iEmailService;

    @PostMapping("/send")
    public String sendEmail(@Valid EmailRequest request) {
        try {
            iEmailService.sendEmail(request);
            return "邮件发送成功！";
        } catch (Exception e) {
            return "邮件发送失败: " + e.getMessage();
        }
    }
}
